Shader "URP-YoFi/Character/Character-Number" 
{
	Properties
	{
        _Color ("Color", Color) = (1,1,1,1)        
        _MainTex ("MainTex", 2D) = "white" {}
        _Number("Number",Range(0,99)) = 0
		
	}

	SubShader 
	{
		Tags
		{
			"RenderType" = "Opaque"
            "Queue" = "AlphaTest"
		}
		cull off
        Offset -1,0
		
		HLSLINCLUDE
		
		#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
		#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
		#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
		
		TEXTURE2D(_MainTex);
		SAMPLER(sampler_MainTex);
		TEXTURE2D(_RMATex);
		SAMPLER(sampler_RMATex);
        TEXTURE2D (_NormalTex);
        SAMPLER(sampler_NormalTex);

		SAMPLER(sampler_linear_repeat);
        SAMPLER(sampler_linear_clamp);

        // UNITY_INSTANCING_BUFFER_START(Props)
        // UNITY_DEFINE_INSTANCED_PROP(uint, _id)
        // UNITY_INSTANCING_BUFFER_END(Props)
		
		CBUFFER_START(UnityPerMaterial)
        half4 _Color;
		float _Number;
		CBUFFER_END
		        
		ENDHLSL

		Pass
		{
			HLSLPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			

			// #pragma multi_compile_instancing

			

			struct Attributes
			{
				float4 positionOS : POSITION;
				float3 normalOS     : NORMAL;
				float2 uv : TEXCOORD0;
				float2 uv2 : TEXCOORD1;
                float4 tangentOS : TANGENT;

			};

			struct Varyings
			{
				float4 positionHCS : SV_POSITION;
				float2 uv : TEXCOORD0;
				float2 uv2 : TEXCOORD1;
				float3 positionWS : TEXCOORD2;
				float3 normalWS  : TEXCOORD3;
                float3 tangentWS :TEXCOORD4;
                float3 BtangentWS : TEXCOORD5;

                float4 screenPos : TEXCOORD6;

				DECLARE_LIGHTMAP_OR_SH(lightmapUV, vertexSH,7);

			};

			Varyings vert (Attributes IN)
			{
				Varyings OUT;
				OUT.uv = IN.uv;
				OUT.uv2 = IN.uv2;
				OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
				OUT.positionWS = TransformObjectToWorld(IN.positionOS.xyz);
                OUT.normalWS = TransformObjectToWorldNormal(IN.normalOS).xyz;
                OUT.tangentWS = TransformObjectToWorldDir(IN.tangentOS.xyz);
                OUT.BtangentWS = cross(OUT.normalWS.xyz,OUT.tangentWS.xyz) * IN.tangentOS.w * unity_WorldTransformParams.w;

				OUT.screenPos = ComputeScreenPos(OUT.positionHCS);

                OUTPUT_LIGHTMAP_UV(IN.uv2, unity_LightmapST, OUT.lightmapUV);
                OUTPUT_SH(OUT.normalWS, OUT.vertexSH);
				return OUT;
			}

			half4 frag (Varyings IN) : SV_Target
			{

				float3 positionWS = IN.positionWS;
                float3 viewDirectionWS = normalize(_WorldSpaceCameraPos.xyz - positionWS);
                float3 normalWS = SafeNormalize(IN.normalWS);
                float3 tangentWS = SafeNormalize(IN.tangentWS);
                float3 bitTangentWS = SafeNormalize(IN.BtangentWS);

                float3 testValue = 0;

				float2 uv = IN.uv;

				half4 color = half4(0,0,0,0);
				float id = round(_Number);
				UNITY_BRANCH
				if(id >= 10)
				{
					float id_right = fmod(id,10.0f);
					float id_left = floor( id / 10.0f);

					float2 uv_right = (uv + float2((float)id_right/2.0f,0) ) / float2(5,1) ;
					float2 uv_left = (uv + float2((float)id_left/2.0f,0) ) / float2(5,1) ;

					half4 number_right = SAMPLE_TEXTURE2D(_MainTex, sampler_linear_repeat, uv_right + float2(- 1.0f/10,0));
					half4 number_left = SAMPLE_TEXTURE2D(_MainTex, sampler_linear_repeat, uv_left);
					float rightMask = step(0.5,uv);
		            color = lerp(number_left,number_right,rightMask) * _Color;
				}
				else
				{
					float2 uv_number = (uv + float2((float)id/2.0f,0) ) / float2(5,1);
					half4 number = SAMPLE_TEXTURE2D(_MainTex, sampler_linear_repeat, uv_number + float2(- 1.0f/20,0));
					float mask1 = step(0.25,uv);
					float mask2 = 1 - step(0.75,uv);
					mask1 *= mask2;
					color = number * _Color * mask1;
				}
				

				

	            clip (color.a - 0.5);
	            half3 finalColor  = color.rgb;
				
				return half4(finalColor,1.0);
			}
			ENDHLSL 
		}
	
	}
}